<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>用户注册</title>

    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="shortcut icon" th:href="@{/user/img/bloglogo.jpg}"/>

    <script th:src="@{/assets/js/jquery.min.js}"></script>
    <script th:src="@{/assets/js/amazeui.min.js}"></script>
    <link rel="stylesheet" th:href="@{/assets/css/amazeui.min.css}"/>
    <link rel="stylesheet" th:href="@{/assets/css/app.css}"/>
</head>
<body>

<div class="log">
    <div class="am-g">
        <div class="am-u-lg-3 am-u-md-6 am-u-sm-8 am-u-sm-centered log-content">
            <h1 class="log-title am-animation-slide-top" style="color: black;" th:text="欢迎注册">~欢迎注册博客~</h1>
            <br>
            <div th:if="${param.error}" style="color: red" th:text="#{login.error}">用户名或密码错误!</div>
            <form class="am-form" id="registerForm">
                <div>
                    <input type="hidden" name="url" th:value="${url}">
                </div>
                <div class="am-input-group am-radius am-animation-slide-left">
                    <input type="text" class="am-radius" th:placeholder="用户名" name="username" />
                    <span class="am-input-group-label log-icon am-radius">
                        <i class="am-icon-user am-icon-sm am-icon-fw"></i>
                    </span>
                </div>
                <br>
                <div class="am-input-group am-animation-slide-left log-animation-delay">
                    <input type="text" class="am-form-field am-radius log-input" th:placeholder="邮箱" name="email" />
                    <span class="am-input-group-label log-icon am-radius">
                        <i class="am-icon-mail-forward am-icon-sm am-icon-fw"></i>
                    </span>
                </div>
                <br>
                <div class="am-input-group am-animation-slide-left log-animation-delay">
                    <input type="password" class="am-form-field am-radius log-input" th:placeholder="密码" name="password" />
                    <span class="am-input-group-label log-icon am-radius">
                        <i class="am-icon-lock am-icon-sm am-icon-fw"></i>
                    </span>
                </div>
                <br>
                <div class="am-input-group am-animation-slide-left log-animation-delay">
                    <input type="password" class="am-form-field am-radius log-input" th:placeholder="确认密码" name="confirmPassword" />
                    <span class="am-input-group-label log-icon am-radius">
                        <i class="am-icon-lock am-icon-sm am-icon-fw"></i>
                    </span>
                </div>
                <div style="padding-top: 10px;">
                    <input type="button" th:value="注册" onclick="register()"
                           class="am-btn am-btn-primary am-btn-block am-btn-lg am-radius am-animation-slide-bottom log-animation-delay" />
                </div>
                <div style="padding-top: 10px;">
                    <input type="button" th:value="返回登录界面" onclick="returnLogin()"
                    class="am-btn am-btn-primary am-btn-block am-btn-lg am-radius am-animation-slide-bottom log-animation-delay" />
                </div>
            </form>
        </div>
    </div>

    <footer class="log-footer">
        <p style="margin: 30px; color: #2E2D3C"><time class="comment-time" th:text="${#dates.format(new java.util.Date().getTime(), 'yyyy')}"></time> &copy; Powered By <a style="color: #0e90d2" rel="nofollow">南城琉璃霞</a></p>
    </footer>
</div>
</body>
<script>
    function register() {
        let username = $('#registerForm input[name=username]').val();
        let email= $('#registerForm input[name=email]').val();
        let password =  $('#registerForm input[name=password]').val();
        let confirmPassword =  $('#registerForm input[name=confirmPassword]').val();
        if (username=='') {
            alert('请输入用户名！');
            return;
        }
        if (email=='') {
            alert('请输入邮箱！');
            return;
        }
        if (password=='') {
            alert('请输入密码！');
            return;
        }
        if (confirmPassword=='') {
            alert('请确认密码！');
            return;
        }
        if (password !=confirmPassword) {
            alert('密码输入不一致！');
            return;
        }
        let params = {
            "username":username,
            "email":email,
            "password":password,
        }
        let url="/register/registerConfirm"
        $.post(url,params)
    }
    function returnLogin(){
        window.location.href="/login"
    }
</script>
</html>